<template>
	<view style="height: 100%;">
		<k-scroll-view ref="k-scroll-view" @onPullDown="handlePullDown" :emptyTip="emptyTip" :bottom="bottom"
			:autoPullUp="true" @onPullUp="handleLoadMore">
			<view style='padding:10px 15px;background-color: white;'>
				<u-search placeholder="请输入查询条件" v-model="keyword" shape="round" :showAction="true" actionText="搜索"
					:animation="false" height='60' style='width:100%' @focus='focusSearch'></u-search>
			</view>
			<view class="planAudit">
				<view class="planAudit_project" v-for="(item,index) in planAudit">
					<view class="planAudit_project_title">
						<image class='planAudit_project_img' src="/static/dailySupervision/tjbg.png" alt=""></image>
						<text>{{item.depName}}</text>
					</view>
					<view class="planAudit_project_content">
						<text class='planAudit_project_text'>检查计划日期</text>
						<text class='planAudit_project_text'>计划检查企业数</text>
						<text class='planAudit_project_text'>已检查/待检查</text>
					</view>
					<view class="planAudit_project_content">
						<text class='planAudit_project_text'>{{item.planTime}}</text>
						<text class='planAudit_project_text'>{{item.planInspCount}}</text>
						<text class='planAudit_project_text' style="color:#1590EF;"
							@click="examineClick(index)">{{item.alreadyInspCount}}/{{item.awaitInspCount}}</text>
					</view>
				</view>
			</view>
		</k-scroll-view>
	</view>
</template>

<script>
	import * as api from '@/common/api/safety.js'
	import kScrollView from '@/components/k-scroll-view/k-scroll-view.vue';
	export default {
		components: {
			kScrollView
		},
		data() {
			return {
				keyword: "",
				planAudit: [],
				formSearch: {},
				emptyTip: '- -已经没有数据啦- -',
				bottom: 200,
				page: {
					"current": 1,
					"size": 10
				},
				pages: '',
				num: 1
			}
		},
		onLoad(option) {
			if (!Object.keys(option).length == 0) {
				this.formSearch = JSON.parse(option.formSearch)
			}
		},
		mounted() {
			this.search()
		},
		methods: {
			search() {
				api.default.getRoutineList({
					...this.page,
					...this.formSearch
				}).then(res => {
					this.planAudit = res.data.data.records
					this.pages = res.data.data.pages
				})
			},

			// 下拉刷新
			handlePullDown(stopLoad) {
				this.search()
			},

			// 上拉刷新
			handleLoadMore(stopLoad) {
				this.num += 1
				if (this.num <= this.pages) {
					api.default.getRoutineList({
						"current": this.num,
						"size": 10,
						...this.formSearch
					}).then(res => {
						this.planAudit = this.planAudit.concat(res.data.data.records);
					})
				} else {
					stopLoad ? stopLoad({
						isEnd: true
					}) : '';
				}

			},
			
			//检查/待检查跳转
			examineClick(index) {
				this.$goBack('./checkTask?direction=1&inspStatus=2&planMonthId=' + this.planAudit[index].id, 2);
			},

			// 我的任务跳转
			focusSearch() {
				this.$goBack('./planSearch', 2);
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		// height: 100%;
		background-color: #F0F0F0;
	}

	.planAudit {
		width: 100%;

		.planAudit_project {
			width: 92%;
			height: 300rpx;
			border-radius: 30rpx;
			margin: 20rpx auto;
			background-color: white;

			.planAudit_project_title {
				width: 94%;
				padding: 10px;
				display: inline-block;
				border-bottom: 1px #F0F0F0 solid;

				.planAudit_project_img {
					width: 30rpx;
					height: 40rpx;
					margin: 0 25rpx 0 20rpx;
					vertical-align: middle
				}
			}

			.planAudit_project_content {
				width: 49%;
				display: inline-block;

				.planAudit_project_text {
					width: 100%;
					display: block;
					margin: 20rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis
				}
			}
		}
	}
</style>
